package org.grailsext.util;

/**
 *
 * @author Wang Yuxing
 */
public class Utils {

	public static boolean containsItem(String[] a, String s) {
		for (int i = 0; i < a.length; i++) {
			String string = a[i];
			if (string.trim().equals(s.trim())) {
				return true;
			}

		}
		return false;
	}

	/**
	 * Check whether equals in array
	 * @param a
	 * @return
	 */
	public static boolean containsEqual(String[] a) {
		for (int i = 0; i < a.length; i++) {
			String s1 = a[i];
			for (int j = i + 1; j < a.length; j++) {
				String s2 = a[j];
				System.out.println("compare " + s1 + " to " + s2);
				if (s1.equals(s2)) {
					return true;
				}
			}
		}
		return false;
	}

	/**
	 *
	 * @param p
	 * @return
	 */
	public static long[] convertStrings2Longs(String[] p) {
		if (p == null || p.length == 0) {
			return null;
		}
		long[] ret = new long[p.length];
		for (int i = 0; i < p.length; i++) {
			ret[i] = Integer.parseInt(p[i]);
		}
		return ret;
	}
}
